#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: target.py 
@version:
@time: 2022/05/31 
"""
from TapClientCore.T04_logic.DagNew.node.node_base import NodeBase


class SyncTarget(NodeBase):
    node = None

    def __init__(self, init_info, table):
        self.init(init_info, table)

    def init(self, init_info, table):
        name = init_info.get('name')
        database_type = init_info.get('database_type')
        sync_type = self.sync_type(database_type)
        connection_id = self.get_connection_id_by_name(name)
        charset = init_info.get('charset')
        if not charset:
            charset = 'utf8'
        node = {
            'stageId': self.newId,
            'tableId': '',
            'tableName': table,
            'connectionId': connection_id,
            'databaseType': database_type,
            'id': self.newId,
            'name': table,
            'type': sync_type,
            'cSql': '',
            'charset': charset,
            'custFields': [],
            'custSql': {
                'cSql': '',
                'conditions': [],
                'editSql': '',
                'fieldFilterType': 'keepAllFields',
                'filterType': 'field',
                'limitLines': '',
                'selectedFields': []
            },
            'dataQualityTag': False,
            'dropTable': False,
            'enableInitialOrder': False,
            'hiddenChangeValue': True,
            'hiddenFieldProcess': True,
            'initialOffset': '',
            'initialSyncOrder': 0,
            'inputLanes': [],
            'isFilter': False,
            'isFirst': True,
            'joinTables': [],
            'outputLanes': [],
            'showBtn': True,
            'sql': '',
        }
        self.node = node
